package com.xix.canal.client.writer.mysql.config;

import com.xixi.canal.client.support.WriterConfig;
import com.xixi.canal.client.support.YmlConfigLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class ConfigLoader {
    private static Logger logger = LoggerFactory.getLogger(ConfigLoader.class);


    public static Map<String, MysqlConfig> load(WriterConfig writerConfig, String destination, Properties properties) {
        logger.info("## Start loading mysql config ... ");
        Map<String, MysqlConfig> ret = new HashMap<>();
        Map<String, String> mysqlFileMap = YmlConfigLoader.loadConfigClassPath(writerConfig.getConfDir(), destination, "mysql");

        mysqlFileMap.forEach((key, value) -> {
            MysqlConfig mysqlConfig = YmlConfigLoader
                    .loadYaml(properties, writerConfig.getConfDir(), destination, MysqlConfig.class, value);
            ret.put(value, mysqlConfig);
        });
        logger.info("## mysql config loaded");
        return ret;
    }
}
